<template>
    <div class="saveUpdate">
        <el-dialog :close-on-click-modal="false" title="编辑收款账号自动下发" :visible.sync="showDialog" @close="$emit('update:showUpdate', false)" :showUpdate="showUpdate" width="500px">
            <el-form :model="DetailInfo" ref="saveChn" label-width="160px" size="mini">
                <el-form-item label="收款账号自动下发要求:">
                    <el-select v-model="DetailInfo.auto_show_level" clearable placeholder="请选择">
                        <el-option v-for="(val,key) of UserLevel" :key="key" :label="val" :value="parseInt(key)"></el-option>
                    </el-select>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="$emit('update:showUpdate', false)" size="small">取 消</el-button>
                <el-button type="primary" :loading="loading" @click="saveDetail" size="small">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { updateAgencyMenber } from '@/api/index'
export default {
    data() {
        return {
            showDialog: this.showUpdate,
            loading: false,
            DetailInfo: {
              auto_show_level: this.$store.state.user.userinfo.auto_show_level
            },
            UserLevel: this.$store.state.app.UserLevel,
        }
    },
    props: {
        showUpdate: {
            type: Boolean,
            default: false
        },
        auto_show_level: {
            type: Number
        }
    },
    methods: {
        saveDetail() {
            updateAgencyMenber(
                this.DetailInfo,
                this.$store.state.user.userinfo.id
            ).then(res => {
                if (res.status === 0) {
                  this.$message.success('修改成功')
                  this.$emit('update:showUpdate', false)
                  this.$store.dispatch('GetInfo')
                }
            })
        }
    },
    watch: {
        showUpdate() {
            this.showDialog = this.showUpdate
        }
    }
}
</script>
